﻿@using Partner.MVC.Models;

@model List<Partner.MVC.Models.House_Server>
@{
    ViewBag.Title = "ServerLists";
    Layout = "~/Views/Shared/Template.cshtml";
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>

@using Partner.MVC.Models;
@{
    var user = Session["LoginUser"] as User_Info;
}

<div style="height: 300px;width: 100%;background:url(/static/hbweb/images/me.jpg);">
    <div class="container">
        <div class="header-message">
            <img class="fl" src="http://pic.huobanchina.com/o_1bp7omfg8e821pc4bbg1u8g1ifl9.jpeg" alt="" />
            <div class="fl header-text">
                <h3 class="user-name">@user.Use_Name </h3>
                <i class="icon-fabu3 point user-namei"></i>
            </div>
            <a id="AlterPwd" style="width:85px;" data-toggle="modal" data-target="#myModal" class="fr fn-font-hover-blue change change-password">
                修改密码
            </a>
        </div>
    </div>
</div>

<div class="bgcSil">
    <div class="container">
        <div class="mt30" style="width: 100%">
            <ul id="divLeft" style="width:24%" class="nav navbar-nav"></ul>
            <div id="divContent" style="width:75%;" class="fr mb80 cont bgcWhit news-list-con">
                <div id="Show">
                    @{
                        <h2 style="margin-left:15%">我的服务</h2>
                        foreach (var item in ViewBag.list)
                        {
                            <table class="table">
                                <tr>
                                    <td style="display:none">@item.S_Id</td>
                                    <td style="width:50%;text-align:center">
                                        <div style="margin-left:30%">
                                            <h3 style="text-align:left">@item.S_Name  
                                           @if (@item.IsUse == 1)
                                           {
                                               <span style="font-size:14px; color:#ccc;">审核通过</span>
                                           }
                                           @if (@item.IsUse == 0)
                                           {
                                            <span style="font-size:14px; color:#ccc;">等待审核</span>
                                           }
                                           </h3>
                                            <div style="text-align:left">@item.S_Intro</div>
                                        </div>
                                    </td>
                                    <td style="width:50%;text-align:center;">
                                        <div style="margin-top:5%">
                                            <input id="Upt" type="button" class="btn btn-primary" value="修改" onclick="upt(@item.S_Id)" />
                                            <input id="Del" type="button" class="btn btn-primary " onclick="del(@item.S_Id)" value="删除" />
                                        </div>

                                    </td>
                                </tr>
                            </table>
                        }
                    }
                </div>
                <div id="uptbyid" style="display:none;margin-left:23%">
                    <div class="personal_info">
                        <h3 style="margin-left:35%;" class="title">服务更新</h3>
                        <div class="fb_box">
                            <table class="table">
                                <tr>
                                    <td><input id="S_Id" type="hidden" /></td>
                                </tr>
                                <tr>
                                    <td><span class="c-red">楼号：</span></td>
                                    <td>
                                        <div class="form-group" style="width:250px">
                                            <select class="form-control" readonly id="S_Type"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td><span>名称</span></td>
                                    <td><input type="text" id="S_Name" readonly class="form-control" style="width:300px" placeholder="内"></td>
                                </tr>
                                <tr>
                                    <td><span>简介</span></td>
                                    <td><input type="text" id="S_Intro" class="form-control" style="width:300px" placeholder=""></td>
                                </tr>
                                <tr>
                                    <td><span>企业介绍</span></td>
                                    <td><textarea class="form-control" id="S_Profile" style="width:300px;height:100px" placeholder="50字以内"></textarea></td>
                                </tr>
                                <tr>
                                    <td><span>电话</span></td>

                                    <td><input type="text" id="S_Telphone" class="form-control" style="width:300px" placeholder=""></td>
                                </tr>
                                <tr style="display:none">

                                    <td><input type="text" id="S_Img" class="form-control" style="width:300px" placeholder="内"></td>
                                    <td><input type="text" id="IsUse" class="form-control" style="width:300px" placeholder="内"></td>

                                </tr>
                                <tr>
                                    <td></td>
                                    <td><button type="button" onclick="UptHouseServer()" class="btn btn-danger btn-lg">修改信息</button></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //删除
    function del(id) {
        if (confirm('确定要删除吗？')) {
            $.ajax({
                type: "post",
                url: "/Merchant/delservice",
                data: { S_Id: id },
                success: function (obj) {

                    if (obj > 0) {
                        alert('删除成功');
                        location.href = '/merchant/serverlist'
                    }
                    else {
                        alert('删除失败')
                    }
                }
            })
        }
    }
    //加载下拉框
    function selectLoad() {
        $.ajax({
            type: "post",
            url: "/merchant/SelectList",
            dataType: "json",
            success: function (obj) {
                //返回 json格式字符串 [{"did":1,"dname":"研发部"}]
                //清空原有内容，添加数据
                $("#S_Type").empty();
                for (var i = 0; i < obj.length; i++) {
                    $("#S_Type").append("<option value='" + obj[i].S_TypeId + "'>" + obj[i].S_Type + "</option>");
                }
            }
        })
    }
    ///反填
    function upt(obj) {
        selectLoad();
        $("#Show").hide();
        $("#uptbyid").show();
        $.ajax({
            type: "post",
            url: "/merchant/GetserverByid",
            data: { S_Id: obj },
            dataType: "json",
            success: function (object) {
                object = eval(object);
                $("#S_Id").val(object.S_Id)
                $("#S_Type").val(object.S_Type)
                $("#S_Name").val(object.S_Name)
                $("#S_Intro").val(object.S_Intro)
                $("#S_Profile").val(object.S_Profile)
                $("#S_Telphone").val(object.S_Telphone)
                $("#IsUse").val(object.IsUse)
                $("#S_Img").val(object.S_Img)
            }
        })
    }
    function UptHouseServer() {
        var regtel = /^1[3578]\d{9}$/;
        var S_Id = $("#S_Id").val();
        var S_Type = $("#S_Type").val();
        var S_Name = $("#S_Name").val();
        var S_Intro = $("#S_Intro").val();
        var S_Profile = $("#S_Profile").val();
        var S_Telphone = $("#S_Telphone").val();
        var S_Img = $("#S_Img").val();
        var IsUse = $("#IsUse").val();
        if (S_Name == "" || S_Name == null) {
            alert('填写信息不能为空')
            return
        }
        else if (S_Intro == "") {
            alert('不能为空')
            return
        }
        else if (S_Profile == "") {
            alert('不能为空')
            return
        }
        else if (!regtel.test(S_Telphone)) {
            alert('手机格式不正确')
            return
        }
        $.ajax({
            type: "post",
            url: "/merchant/UptHouseSouse",
            data: { S_Id: S_Id, S_Type: S_Type, S_Name: S_Name, S_Intro: S_Intro, S_Profile: S_Profile, S_Telphone: S_Telphone, S_Img: S_Img, IsUse: IsUse },
            success: function (obj) {
                if (obj > 0) {
                    alert('修改成功');
                    location.href = '/merchant/serverlist'
                }
                else {
                    alert('修改失败');
                }
            }
        })
    }
</script>

<script>
    ParentNav();
    // 绑定根节点
    function ParentNav() {
        $.ajax({
            type: "post",
            url: "/Partner/LeftNav",
            dataType: "json",
            success: function (data) {
                var htmltab = "";
                for (var i = 0; i < data.length; i++) {
                    htmltab += "<li class=\"dropdown\"><a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" style=\"width: 175px;font-size: 16px;\">" + data[i].Lar_Name + "</a>" + SonNav(data[i].Limit_Id) + "</li>";
                }
                $("#divLeft").append(htmltab);
            },
            error: function (err) {
                alert(err);
            }
        })
    }
    // 绑定子节点
    function SonNav(id) {
        var html1 = "";
        $.ajax({
            type: "post",
            url: "/Partner/LeftSon",
            data: { pid: id },
            dataType: "json",
            async: false,
            success: function (data) {
                var strhtml = "<ul class=\"dropdown-menu\">"
                for (var i = 0; i < data.length; i++) {
                    strhtml += "<li><a href=\"" + data[i].Limit_Url + "\">" + data[i].Limit_Name + "</a></li>"
                }
                strhtml += "</ul>";
                html1 = strhtml;
            }
        })
        return html1;
    }
</script>
